package com.caijb.redisdemo.controller;

import com.caijb.redisdemo.dto.request.GameRequest;
import com.caijb.redisdemo.monitor.GameMonitor;
import com.caijb.redisdemo.monitor.TestMonitor;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.Duration;
import java.time.Instant;

/**
 * @author caijb
 * @version 1.0
 * @data 2025/11/7 01:43
 */
@RestController
public class TestMonitorController {

    @Resource
    private TestMonitor testMonitor;

    @Resource
    private GameMonitor gameMonitor;

    @RequestMapping("/testMonitor")
    public String testMonitor(@RequestBody GameRequest gameRequest) throws InterruptedException {
        Instant start = Instant.now();
        Thread.sleep(500L);
        testMonitor.successCount(gameRequest.getUserId(), gameRequest.getGameName(), gameRequest.getGameType(), 1L);
        Duration responseTime = Duration.between(start, Instant.now());
        testMonitor.recordResponseTime("李四","王者荣耀","排位赛", responseTime);
        return "success";
    }

    @RequestMapping("/testMonitorByAnno")
    public String testMonitorByAnno() throws InterruptedException {
        Thread.sleep(500L);
        gameMonitor.count("张三","王者荣耀","排位赛");
        return "success";
    }
}
